/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;

/**
 *
 * @author dloaiza
 */
@Entity
@Table(name = "TAB_EMPRESA")
@NamedQueries({
    @NamedQuery(name = "Empresa.findAll", query = "SELECT e FROM Empresa e")})
public class Empresa implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "DSNIT", nullable = false, length = 20)
    private String dsnit;
    @Column(name = "DSRAZON_SOCIAL", length = 200)
    private String dsrazonSocial;
    @Column(name = "DSDIRECCION", length = 200)
    private String dsdireccion;
    @OneToMany(mappedBy = "dsidEmpresa", fetch = FetchType.LAZY)
    private List<Usuario> usuarioList;
    @JoinColumn(name = "DSID_CONTACTO", referencedColumnName = "DSIDENTIFICACION")
    @ManyToOne(fetch = FetchType.LAZY)
    private Contacto dsidContacto;

    public Empresa() {
    }

    public Empresa(String dsnit) {
        this.dsnit = dsnit;
    }

    public String getDsnit() {
        return dsnit;
    }

    public void setDsnit(String dsnit) {
        this.dsnit = dsnit;
    }

    public String getDsrazonSocial() {
        return dsrazonSocial;
    }

    public void setDsrazonSocial(String dsrazonSocial) {
        this.dsrazonSocial = dsrazonSocial;
    }

    public String getDsdireccion() {
        return dsdireccion;
    }

    public void setDsdireccion(String dsdireccion) {
        this.dsdireccion = dsdireccion;
    }

    public List<Usuario> getUsuarioList() {
        return usuarioList;
    }

    public void setUsuarioList(List<Usuario> usuarioList) {
        this.usuarioList = usuarioList;
    }

    public Contacto getDsidContacto() {
        return dsidContacto;
    }

    public void setDsidContacto(Contacto dsidContacto) {
        this.dsidContacto = dsidContacto;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (dsnit != null ? dsnit.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Empresa)) {
            return false;
        }
        Empresa other = (Empresa) object;
        if ((this.dsnit == null && other.dsnit != null) || (this.dsnit != null && !this.dsnit.equals(other.dsnit))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.alexstarkbd.jpa.entities.Empresa[ dsnit=" + dsnit + " ]";
    }
    
    @PostLoad
    public void fixIt(){
        this.usuarioList = new ArrayList<Usuario>(this.usuarioList);
    }
    
    
}
